import fang from '../../models/Fang';
import Cache from '../../utils/Cache';

Page({
  data: {
    fangs: [],
    page: 1,
    topNum: 0,
    showTop: true
  },
  onLoad(options) {
    this.getMore();
  },
  getMore() {
    let page = this.data.page;
    // 房源列表
    if (!Cache.has('favlist')) {
      fang.favList(page).then( ret => {
        if (ret.data.data.data.length > 0) {
          this.setData({
            fangs: [ ...this.data.fangs, ...ret.data.data.data],
            page: ++page,
          });
        } else {
          Cache.set('favlist',true,10);
          wx.showToast({
            title: '没有更多最新的数据了',
            icon: 'none',
            duration: 1500,
            mask: true,
          });
        }
      });
    }
  },
  scrollTop(evt) {
    let scrollTop = evt.detail.scrollTop;
    
    let showTop = true;

    if (scrollTop >= 100) {
      showTop = false;
    }

    this.setData({ showTop });
  },
  goTo() {
    this.setData({
      topNum: 0
    })
  }
})